package com.ks.utils.paging;

/**
 * 
 * @author jxzhang
 *
 */
public class Page {

	// 页码
	private int pageNo = 1;

	// 每页显示的行数
	private int pageSize = 3;

	// 起始行
	private int begin;
	
	// 结束行（假分页作为for里的max值）
	private int end;

	// 总数条数
	private int countItem;// 调用这方法就时必须先dao查出

	// 总页数
	private int pageCount;

	public Page() {
	}

	public Page(int pageNo, int pageSize) {
		super();
		this.pageNo = pageNo;
		this.pageSize = pageSize;
	}

	public Page(int pageNo, int pageSize, int countItem) {
		super();
		this.pageNo = pageNo;
		this.pageSize = pageSize;
		this.countItem = countItem;
	}

	/**
	 * 计算总页数
	 */
	public int getPageCount() {
		if (countItem % pageSize == 0) {
			pageCount = countItem / pageSize;
		} else {
			pageCount = countItem / pageSize + 1;
		}
		return pageCount;
	}

	/**
	 * 计算起始行
	 */
	public int getBegin() {
		return (pageNo - 1) * pageSize;
	}

	public static void main(String[] args) {
		Page page = new Page(1, 3, 8);
		System.out.println(page.getBegin());
		System.out.println(page.getPageCount());
	}

	/**
	 * 结束行
	 * @return
	 */
	public int getEnd() {
		return this.getBegin() + this.getPageSize();
	}

	public void setEnd(int end) {
		this.end = end;
	}

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public void setBegin(int begin) {
		this.begin = begin;
	}

	public int getCountItem() {
		return countItem;
	}

	public void setCountItem(int countItem) {
		this.countItem = countItem;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

}
